#include <stdio.h>                                               
#include <unistd.h>                                              
#include <sys/types.h>                                           
#include <stdlib.h>                                              
#include <sys/wait.h>                                            

int main()
{
    pid_t id = fork();
    if (id < 0)
    {
        perror("fork error");
        exit(-1);
        //错误情况                                               
    }
    if (id == 0)
    {
        //child process                                          
        int cnt = 5;
        while (cnt--)
        {
            printf("i am a child process pid:%d\n", getpid());;
            sleep(1);
        }
        exit(0);//process exit                                   
    }
    sleep(10);//wait child process                               
    printf("i am a father pid:%d\n", getpid());
    pid_t ret = wait(NULL);
    if (ret >= 0) printf("father wait:%d,success\n", ret);
    else ("father wait failed\n");
    sleep(10);
    return 0;
}
